<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@include file="/commons/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<fmt:bundle basename="res">
<head>
    <meta charset="utf-8">
    <title><fmt:message key='lb' /></title>
    <jsp:include page="/WEB-INF/commons/commons-header.jsp" flush="true"/>
    <style>
        .feijin-split {
            border-left: 1px dashed #ccc;
        }
    </style>
</head>
<body>

<div class="layui-fluid">


    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <form name="totalForm" id="totalForm" method="get">

                    <div class="layui-inline">
                        <label class="layui-form-label"><fmt:message key='mbmc' /></label>
                        <div class="layui-input-inline">
                            <input type="text" name="name" placeholder="<fmt:message key='qsrddmc' />" value="<c:if test='${params.name !=null}'>${params.name}</c:if>" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label"><fmt:message key='jjfs' /></label>
                        <div class="layui-input-inline">
                            <select lay-verify="required" name="type">
                                <option value="0" <c:if test="${params.type eq 0}">selected="selected"</c:if>><fmt:message key='qxz' /></option>
                                <option value="1" <c:if test="${params.type eq 1}">selected="selected" </c:if>><fmt:message key='azl' /></option>
                                <option value="2" <c:if test="${params.type eq 2}">selected="selected"</c:if>><fmt:message key='ajs' /></option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label"><fmt:message key='zt' /></label>
                        <div class="layui-input-inline">
                            <select lay-verify="required" name="status">
                                <option value="0" <c:if test="${params.status eq 0}">selected="selected"</c:if>><fmt:message key='qxz' /></option>
                                <option value="1" <c:if test="${params.status eq 1}">selected="selected" </c:if>><fmt:message key='qy' /></option>
                                <option value="2" <c:if test="${params.status eq 2}">selected="selected"</c:if>><fmt:message key='jy' /></option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-sm layuiadmin-btn-list" id="search"><i class="layui-icon layui-icon-search layuiadmin-button-btn"></i> <fmt:message key='ss' /></button>
                    </div>

                </form>
            </div>
        </div>
    </div>

    <div class="layui-card">
        <div class="layui-field-box layui-form">

            <a href="javascript:void(0);" class="layui-btn layui-btn-sm layui-btn-normal" id="add"><i class="layui-icon">&#xe61f;</i> 添加运费模板</a>

            <table class="layui-table" lay-size="sm">
                <thead>
                <%--<th width="5%">--%>
                <%--<input id="checkboxs" type="checkbox" value="${item.id}" lay-ignore lay-skin="primary"/>--%>
                <%--</th>--%>
                <th><fmt:message key='mbmc' /></th>
                <th><fmt:message key='mblx' /></th>
                <th><fmt:message key='szdwk' /></th>
                <th><fmt:message key='sfdwy' /></th>
                <th><fmt:message key='xzdwk' /></th>
                <th><fmt:message key='xfdwy' /></th>
                <th><fmt:message key='xjdwj' /></th>
                <th><fmt:message key='sfdwy' /></th>
                <th><fmt:message key='xjdwj' /></th>
                <th><fmt:message key='xfdwy' /></th>
                <th><fmt:message key='zt' /></th>
                <th><fmt:message key='shijian' /></th>
                <th><fmt:message key='cz' /></th>
                </thead>
                <c:forEach items="${page.result}" var="item" varStatus="status">
                    <tr>
                            <%--<td>--%>
                            <%--<c:if test="${item.status eq 1}">--%>
                            <%--<input type="checkbox" value="${item.id}" class="feijin-check" lay-ignore lay-skin="primary"/>--%>
                            <%--</c:if>--%>
                            <%--</td>--%>
                        <td>${item.name}</td>
                        <td>
                            <c:choose>
                                <c:when test="${item.type eq '1'}"><fmt:message key='azl' /></c:when>
                                <c:when test="${item.type eq '2'}"><fmt:message key='ajj' /></c:when>
                            </c:choose>
                        </td>
                        <c:choose>
                            <c:when test="${item.type eq '1'}">
                                <td>${item.defaultWeight} <fmt:message key='k' /></td>
                                <td><fmt:formatNumber value="${item.defaultWeightAmount}" type="CURRENCY"/> <fmt:message key='y' /></td>
                                <td>${item.defaultAddWeight} <fmt:message key='k' /></td>
                                <td><fmt:formatNumber value="${item.defaultAddWeightAmount}" type="CURRENCY"/> <fmt:message key='u' /></td>
                                <td>-</td>
                                <td>-</td>
                                <td>-</td>
                                <td>-</td>
                            </c:when>
                            <c:when test="${item.type eq '2'}">
                                <td>-</td>
                                <td>-</td>
                                <td>-</td>
                                <td>-</td>
                                <td>${item.defaultPiece} <fmt:message key='j' /></td>
                                <td><fmt:formatNumber value="${item.defaultPieceAmount}" type="CURRENCY"/> <fmt:message key='y' /></td>
                                <td>${item.defaultAddPiece} <fmt:message key='j' /></td>
                                <td><fmt:formatNumber value="${item.defaultAddPieceAmount}" type="CURRENCY"/> <fmt:message key='y' /></td>
                            </c:when>
                        </c:choose>
                                <td>
                                    <c:choose>
                                        <c:when test="${item.status eq 1}"><fmt:message key='qy' /></c:when>
                                        <c:otherwise><fmt:message key='jy' /></c:otherwise>
                                    </c:choose>
                                </td>
                                <td><fmt:formatDate value="${item.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
                        <td>
                            <div class="layui-btn-container">
                                <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs feijin-modify"><fmt:message key='bj' /></a>

                                <c:choose>
                                    <c:when test="${item.status eq 1}">
                                        <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-danger layui-btn-xs feijin-locked"><fmt:message key='jy' /></a>
                                    </c:when>
                                    <c:otherwise>
                                        <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-normal layui-btn-xs feijin-unlocked"><fmt:message key='qy' /></a>
                                    </c:otherwise>
                                </c:choose>

                                    <%--<a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs feijin-detail">查看</a>--%>
                            </div>
                        </td>
                    </tr>
                </c:forEach>
            </table>
            <jsp:include page="/commons/page.jsp" flush="true"/>
        </div>
    </div>

</div>

<script>

    $(function () {

        //添加运费模板
        $("#add").click(function () {
            layer.open({
                type: 2
                , title: '<fmt:message key='tjyfmb' />'
                , content: '${web_domain}/merchant/freight/create'
                , maxmin: true
                , area: ['97%', '97%']
                , btn: ['<fmt:message key='bc' />', '<fmt:message key='qx' />']
                , yes: function (index, layero) {
                    var submit = layero.find('iframe').contents().find("#submit");
                    submit.click();
                }
            });
        });

        $(".feijin-modify").click(function () {

            var id = $(this).attr("data-id");

            layer.open({
                type: 2
                , title: '<fmt:message key='bjsp' />'
                , content: '${web_domain}/merchant/freight/' + id + '/modify'
                , maxmin: true
                , area: ['97%', '97%']
                , btn: ['<fmt:message key='bc' />', '<fmt:message key='qx' />']
                , yes: function (index, layero) {
                    var submit = layero.find('iframe').contents().find("#submit");
                    submit.click();
                }
            });
        });


        //禁用
        $(".feijin-locked").click(function () {
            var id = $(this).attr("data-id");
            layui.use('layer', function () {
                var layer = layui.layer;
                layer.open({
                    type: 0,
                    title: '<fmt:message key='jyyfmb' />',//自定义标题样式
                    border: [0],
                    content: '<span class="orange"><fmt:message key='qrjym' /></span>',
                    btn: ['<fmt:message key='jy' />', '<fmt:message key='qx' />'],
                    yes: function () {
                        $.ajax({
                            type: "post",
                            url: "${web_domain}/merchant/freight/disable",
                            dataType: "json",
                            data: {
                                "id": id,
                                "_method": "put"
                            },
                            success: function (data) {
                                location.reload();
                            }
                        });
                    },
                    no: function () {
                        layer.close(index);
                    }
                });
            });
        });

        //启用
        $(".feijin-unlocked").click(function () {
            var id = $(this).attr("data-id");
            layui.use('layer', function () {
                var layer = layui.layer;
                layer.open({
                    type: 0,
                    title: '<fmt:message key='qyyfmb' />',//自定义标题样式
                    border: [0],
                    content: '<span class="orange"><fmt:message key='qrqym' /></span>',
                    btn: ['<fmt:message key='qy' />', '<fmt:message key='qx' />'],
                    yes: function () {
                        $.ajax({
                            type: "post",
                            url: "${web_domain}/merchant/freight/enabled",
                            dataType: "json",
                            data: {
                                "id": id,
                                "_method": "put"
                            },
                            success: function (data) {
                                location.reload();
                            }
                        });
                    },
                    no: function () {
                        layer.close(index);
                    }
                });
            });
        });

    });
</script>
</body>
</fmt:bundle>
</html>
